gtk-demo: Make editable cells demo more robust
authorMatthias Clasen <mclasen@redhat.com>
Mon, 19 Jan 2015 12:32:31 +0000 (07:32 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 19 Jan 2015 12:36:08 +0000 (07:36 -0500)
When removing all rows, trying to add rows would not work
and throw criticals. This is fallout from a recent change
to insert rows at the right position. Fix this by handling
the 'empty model' case separately.

https://bugzilla.gnome.org/show_bug.cgi?id=743157

demos/gtk-demo/editable_cells.c

index 18ff4771edfa3a2526dfaedb3f16cedbb0599035..717bf50fdc53fd501575f8b88f7fd26c8f74b3e6 100644 (file)
@@ -158,11 +158,18 @@ add_item (GtkWidget *button, gpointer data)
   /* Insert a new row below the current one */
   gtk_tree_view_get_cursor (treeview, &path, NULL);
   model = gtk_tree_view_get_model (treeview);
-  gtk_tree_model_get_iter (model, &current, path);
-  gtk_tree_path_free (path);
+  if (path)
+    {
+      gtk_tree_model_get_iter (model, &current, path);
+      gtk_tree_path_free (path);
+      gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, &current);
+    }
+  else
+    {
+      gtk_list_store_insert (GTK_LIST_STORE (model), &iter, -1);
+    }
 
   /* Set the data for the new row */
-  gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, &current);
   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                       COLUMN_ITEM_NUMBER, foo.number,
                       COLUMN_ITEM_PRODUCT, foo.product,